package com.gome.han.bigdata.mr._010_grouping_comparator;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * @author Hanpeng
 * @date 2020/12/1 15:52
 * @description:
 */
public class OrderGroupingComparator extends WritableComparator {
    protected OrderGroupingComparator(){
        super(OrderBean.class, true);
    }
    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        // 要求只要id相同，就认为是相同的key
        OrderBean aBean = (OrderBean) a;
        OrderBean bBean = (OrderBean) b;
        int result;
        if (aBean.getOrderId() > bBean.getOrderId()) {
            result = 1;
        }else if(aBean.getOrderId() < bBean.getOrderId()){
            result = -1;
        }else {
            result = 0;
        }
        return result;
    }
}
